<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'资源添加', styles:'bootstrap,font-awesome,animate,style,dtvalidate,layer,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;}
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-offset-1 col-sm-10" style="margin-left: -10px;width: 100%;">
                <button type="button" class="return-btn btn btn-w-m btn-primary">返回</button>
                <div style="border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 4px 0px;padding-bottom: 15px;margin-top: 10px;" ></div>
            </div>
        </div>
    </div>
</div>
<!-- START 内容部分 -->
<div class="container" >
    <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
        <div class="form-group">
            <label class="control-label col-sm-2">渠道</label>
            <div class="col-sm-6">
                <select id="relatedChannelName" name="relatedChannelName" class="form-control">
                    <option value="">全部分类</option>
                    <%for(var dict in channel){%>
                    <option value="${dict.channelName}"  >${dict.channelName}</option>
                    <%}%>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">SKU</label>
            <div class="col-sm-6">
                <div class="input-group">
                    <input type="text" id="relatedSku" name="relatedSku" class="form-control">
                    <span class="input-group-btn">
                        <button type="button" class="search-product btn btn-primary">搜索</button>
                    </span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">类别</label>
            <div class="col-sm-2">
                <input type="text" id="bigCategory" class="form-control" disabled="disabled" value="">
            </div>
            <div class="col-sm-2">
                <input type="text" id="midCategory" class="form-control" disabled="disabled" value="">
            </div>
            <div class="col-sm-2">
               <input type="text" id="smallCategory" class="form-control" disabled="disabled" value="">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">产品名称</label>
            <div class="col-sm-6">
                <input type="text" readonly id="relatedProductName" name="relatedProductName"  class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">FNSKU</label>
            <div class="col-sm-6">
                <input type="text" id="relatedFnSku" name="relatedFnSku"  class="form-control"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">ASIN</label>
            <div class="col-sm-6">
                <input type="text" id="relatedAsin" name="relatedAsin"  class="form-control"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">运营人员</label>
            <div class="col-sm-6">
                <select id="relatedOperateName" name="relatedOperateName" xm-select="relatedOperateName" xm-select-radio xm-select-search>
                    <option value=""></option>
                    <%for(var dict in operate){%>
                    <option value="${dict.userRealname}"  >${dict.userRealname}</option>
                    <%}%>
                </select>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
                <button type="button" class="return-btn btn btn-warning">
                    <i class="fa fa-save"></i> 返回
                </button>
            </div>
        </div>
    </form>
</div>
<!-- END 内容部分 -->

<!-- START 公共脚本 -->
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,chosen,chosen-demo'}){}%>
<!-- END 公共脚本 -->
<script>
    var cvalidator;
    $(function(){
        formSelects.render('relatedOperateId');

        //初始化验证器
        cvalidator = $.fn.dlshouwen.validator.init($('#info-form'));

        $("#relatedChannelId").change(function () {
            $("#relatedChannelName").val($("#relatedChannelId").find("option:selected").text());
        });
        $('.search-product').on('click',function () {
            var index = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var relatedSku=$("#relatedSku").val();
            if(relatedSku==''){
                parent.layer.msg('请先填写SKU！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            $.post('/sea/product/product/findBySku.do?sku='+relatedSku,function(data){
                if( data.ok ){
                    $("#relatedProductName").val(data.data.productName);
                    $("#smallCategory").val(data.data.productClassName);
                    $("#midCategory").val(data.data.productMidClassName);
                    $("#bigCategory").val(data.data.productBigClassName);
                    layer.close(index);
                }else{
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });

        //提交表单
        $('.save-btn').on('click',function(){
            var relatedChannelId=$("#relatedChannelId").val();
            if(relatedChannelId==''){
                parent.layer.msg('请选择渠道！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var relatedSku=$("#relatedSku").val();
            if(relatedSku.length<=0||relatedSku==''){
                parent.layer.msg('请填写SKU！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }

            var relatedProductName=$("#relatedProductName").val();
            if(relatedProductName.length<=0||relatedProductName==''){
                parent.layer.msg('请填写正确的SKU！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            //数据提交
            $.post('/sea/operate/relatedSku/save.do',$('#info-form').serialize(),function(data){
                if( data.ok ){
                    parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                        parent.$relatedTable.bootstrapTable('refresh');
                        parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
                    });
                }else{
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                }
            });
        });
        //返回
        $('.return-btn').on('click',function(){
            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
        });
    });
</script>
</body>
</html>